#!/bin/bash node

const OSS = require('ali-oss')
const fs = require('fs');
const ALYKEY = process.env.ALYKEY

const accessKeyId = ALYKEY.split('+')[0].split('-')[1]
const accessKeySecret = ALYKEY.split('+')[1].split('-')[1]
console.log(arg)
let client = new OSS({
  region: 'cn-qingdao',
  accessKeyId,
  accessKeySecret,
  bucket: 'cdn-hterobot',
});

async function putStream () {
  try {
  
  let stream = fs.createReadStream('local-file');
  let result = await client.putStream('object-name', stream);
  console.log(result);

  // don't use 'chunked encoding'
  let stream = fs.createReadStream('local-file');
  let size = fs.statSync('local-file').size;
  let result = await client.putStream(
    'object-name', stream, {contentLength: size});
  console.log(result);
  } catch (e) {
    console.log(e)
  }
}

putStream();